from collections import Counter
from typing import List


class Solution:
    def topKFrequent(self, nums: List[int], k: int) -> List[int]:
        dicts = dict(Counter(nums))
        d = sorted(dicts.keys(), key=lambda x: -dicts[x])
        return d[:k]


if __name__ == '__main__':
    s = Solution()
    r = s.topKFrequent([1, 1, 1, 2, 2, 3], k=2)
    print(r)
